import unittest
from api.login import LoginAPI
import app
import json
from parameterized import parameterized


def budile_data():
    file = app.BASE_DIR+"/data/login.json"
    test_data =[]
    with open(file,"r",encoding="utf-8") as f:
        json_data =json.load(f)
        for case_data in json_data:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            success = case_data.get("success")
            code = case_data.get("code")
            message = case_data.get("message")
            test_data.append((login_data,status_code,success,code,message))
        return test_data



class IHRM_LOGIN(unittest.TestCase):
    def setUp(self):
        self.login_api =LoginAPI()
    def tearDown(self):
        pass
    @parameterized.expand(budile_data())
    def test01_case001(self,login_data,status_code,success,code,message):
        response = self.login_api.login(login_data)
        # print(login_data.get("mobile"))
        print(response.json())
        self.assertEqual(status_code,response.status_code)
        self.assertEqual(success,response.json().get("success"))
        self.assertEqual(code,response.json().get("code"))
        self.assertIn(message,response.json().get("message"))
        if response.json().get("data") is not None:
            app.TOKEN = "Bearer " + response.json().get("data")
            print(app.TOKEN)
            app.headers_data["Authorization"] = app.TOKEN
            print(app.headers_data)